﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Text;


public partial class kecheng_mp_ManageClass : System.Web.UI.MasterPage
{
    public int title_id;
    protected void Page_Load(object sender, EventArgs e)
    {
        //初始化title_id共享变量
        if (Request.QueryString["title_id"] != null)
        {
            title_id = Convert.ToInt32(Request.QueryString["title_id"]);
        }
        else
        {
            LinkButton1.Enabled = false;
            //modify.Text = "添加";
            delete.CssClass = "unable";
            sort.CssClass = "unable";
            upLoad.CssClass = "unable";
            view.CssClass = "unable";

            modify.Enabled = false;
            delete.Enabled = false;
            sort.Enabled = false;
            upLoad.Enabled = false;
            view.Enabled = false;
        }
        if (Session["sconfirm"].ToString() == "终审通过")//终审通过的课程不能修改和上传视频
        {
            modify.Enabled = false;
            upLoad.Enabled = false;
        }
        modify.NavigateUrl= string.Format(string.Format("~/kecheng_mp/edit.aspx?title_id={0}", title_id));
        delete.NavigateUrl = string.Format(string.Format("~/kecheng_mp/delete.aspx?title_id={0}", title_id));
        string videoPlayPath = ConfigurationManager.AppSettings["VideoPlayPath"];
        string userName = Session["username"].ToString();
        sort.NavigateUrl = string.Format("{0}/sort.aspx?cba={1}&gef={2}", videoPlayPath, Convert.ToBase64String(Encoding.Default.GetBytes(userName)), Convert.ToBase64String(Encoding.Default.GetBytes(title_id.ToString())));
        upLoad.NavigateUrl = string.Format("{0}/upload.aspx?cba={1}&gef={2}", videoPlayPath, Convert.ToBase64String(Encoding.Default.GetBytes(userName)), Convert.ToBase64String(Encoding.Default.GetBytes(title_id.ToString())));
        view.NavigateUrl = string.Format("~/kecheng_mp/viewplay.aspx?id={0}",title_id);
        //用户权限检查，检查用户session是否有效
        if (Session["userName"] != null)
        {
            //检查用户是否具有访问此页面的权限
        }
        else
        {
        }
    }
    protected void modify_Click(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["gConnectionString"]);
        conn.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = conn;
        com.CommandType = CommandType.Text;

        string sql = "delete  from bbs where title_id=@title_id";
        com.CommandText = sql;
        com.Parameters.Clear();
        com.Parameters.AddWithValue("@title_id", title_id);
        if (com.ExecuteNonQuery()>0)
        {
            sql = "delete  from imgUpLoad where title_id=@title_id";
            com.CommandText = sql;
            com.ExecuteNonQuery();
            Response.Write("<script language='javascript'>alert('删除成功！');window.parent.location.reload();</script>");

        }
        else
        {
            Response.Write("<script language='javascript'>alert('删除失败！');</script>");
        }
        com.Dispose();
        conn.Dispose();
        
    }
}
